define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pan_good/index' + location.search,
                    add_url: 'pan_good/add',
                    edit_url: 'pan_good/edit',
                    del_url: 'pan_good/del',
                    multi_url: 'pan_good/multi',
                    table: 'pan_good',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name')},
                        {field: 'img', title: __('Img'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"huafei":__('Status huafei'),"diyong":__('Status diyong'),"zhongzi":__('Status zhongzi'),"exp":__('Status exp')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();



            $("input:radio[name='row[status]']").change(function (){

                var val =  $(this).val();
                if(val=='zhongzi'){
                    $('#shop').show();
                    $('#diyong').hide();
                    $('#huafei').hide();
                    $('#exp').hide();
                }
                if(val=='diyong'){
                    $('#diyong').show();
                    $('#shop').hide();
                    $('#huafei').hide();
                    $('#exp').hide();
                }
                if(val=='huafei'){
                    $('#huafei').show();
                    $('#shop').hide();
                    $('#diyong').hide();
                    $('#exp').hide();
                }
                if(val=='exp'){
                    $('#huafei').hide();
                    $('#shop').hide();
                    $('#diyong').hide();
                    $('#exp').show();
                }

            });
            
        },
        edit: function () {
            Controller.api.bindevent();

            var moren = $("input[name='row[status]']:checked").val();
            console.log(moren);
            if(moren=='shop'){
                $('#shop').show();
                $('#diyong').hide();
                $('#huafei').hide();
            }
            if(moren=='diyong'){
                $('#diyong').show();
                $('#shop').hide();
                $('#huafei').hide();
            }
            if(moren=='huafei'){
                $('#huafei').show();
                $('#shop').hide();
                $('#diyong').hide();
            }

            $("input:radio[name='row[status]']").change(function (){

                var val =  $(this).val();
                if(val=='zhongzi'){
                    $('#shop').show();
                    $('#diyong').hide();
                    $('#huafei').hide();
                    $('#exp').hide();
                }
                if(val=='diyong'){
                    $('#diyong').show();
                    $('#shop').hide();
                    $('#huafei').hide();
                    $('#exp').hide();
                }
                if(val=='huafei'){
                    $('#huafei').show();
                    $('#shop').hide();
                    $('#diyong').hide();
                    $('#exp').hide();
                }
                if(val=='exp'){
                    $('#huafei').hide();
                    $('#shop').hide();
                    $('#diyong').hide();
                    $('#exp').show();
                }
            });
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});